package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.VolumeReply;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeVolume implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,SPEAKER,000821,2,095325,A,2250.2256,N,11391.6190,E,0.18,162,030621,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber=split[4];
        String speakLevel=split[5];//(2，1，0) 分别对应大中小,设备已经获取的音量设置
        String deviceTime = split[6];
        String latitude = split[8];
        String longitude = split[10];
        String speed = split[12];
        String orientation = split[13];
        String deviceDate = split[14];
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(longitude, latitude);
        LocationData locationData = new LocationData();
        locationData.setOrientation(Integer.parseInt(orientation));
        locationData.setSpeed(Double.parseDouble(speed));
        locationData.setLatitude(list.get(1));
        locationData.setLongitude(list.get(0));
        VolumeReply volumeReply = new VolumeReply();
        volumeReply.setCommandNumber(commandNumber);
        volumeReply.setImei(imei);
        volumeReply.setDeviceDate(deviceDate);
        volumeReply.setDeviceStatus(deviceStatus);
        volumeReply.setDeviceTime(deviceTime);
        volumeReply.setSpeakLevel(Integer.parseInt(speakLevel));
        volumeReply.setLocationData(locationData);
        return structureMessage(Constants.REPLY,Constants.CMD_ADJUST_VOLUME,false,"",volumeReply);
    }
}
